package com.ruanyun.modular.admin.mapper;

import com.ruanyun.base.pojo.page.LayuiPageInfo;
import com.ruanyun.modular.admin.entity.TProposedMeasuresPlan;
import com.ruanyun.modular.admin.entity.VocsEmission;
import com.ruanyun.modular.admin.model.params.VocsEmissionParam;
import com.ruanyun.modular.admin.model.result.VocsEmissionResult;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * vocs排放量 Mapper 接口
 * </p>
 *
 * @author 
 * @since 2021-04-28
 */
@Repository
public interface VocsEmissionMapper extends BaseMapper<VocsEmission> {

    /**
     * 获取列表
     *
     * @author 
     * @Date 2021-04-28
     */
    List<VocsEmissionResult> customList(@Param("paramCondition") VocsEmissionParam paramCondition);

    /**
     * 获取map列表
     *
     * @author 
     * @Date 2021-04-28
     */
    List<Map<String, Object>> customMapList(@Param("paramCondition") VocsEmissionParam paramCondition);

    /**
     * 获取分页实体列表
     *
     * @author 
     * @Date 2021-04-28
     */
    Page<VocsEmissionResult> customPageList(@Param("page") Page page, @Param("paramCondition") VocsEmissionParam paramCondition);

    Page<VocsEmissionResult> customPageList1(@Param("page") Page page, @Param("paramCondition") VocsEmissionParam paramCondition);

    /**
     * 获取分页map列表
     *
     * @author 
     * @Date 2021-04-28
     */
    Page<Map<String, Object>> customPageMapList(@Param("page") Page page, @Param("paramCondition") VocsEmissionParam paramCondition);

    /*根据companyId 查询是否存在数据*/
    @Select("SELECT * FROM vocs_emission WHERE company_id = #{companyId}  and del_flag != 2 ")
    List<VocsEmissionResult> getDetails(@Param("companyId") Long companyId);


    Page<VocsEmissionResult> getVocsEmissionPage(@Param("pageContext") Page pageContext, @Param("companyId") Integer companyId,@Param("emissionWay") Integer emissionWay);

    @Select("SELECT\n" +
            "\tv.*, b.company_name AS companyName\n" +
            "FROM\n" +
            "\tvocs_emission v\n" +
            "LEFT JOIN t_basicinfo b ON v.company_id = b.id\n" +
            "WHERE\n" +
            "\tv.company_id = #{companyId}  and v.del_flag != 2 ")
    List<VocsEmissionResult> getVocsEmissionList(Integer companyId);

    Page  getEmissionSummary(@Param("page") Page page, @Param("paramCondition") VocsEmissionParam paramCondition);


    List<VocsEmissionResult>  getTotalSummary(@Param("paramCondition") VocsEmissionParam paramCondition);

    @Select("SELECT IFNULL(SUM(emissions_num),0)as actualEmissions, units FROM vocs_emission WHERE company_id = #{companyId} AND del_flag != 2")
    VocsEmissionResult getActualEmissions(@Param("companyId") Integer companyId);

    VocsEmissionResult getEmissionSummarys(@Param("companyId") Integer companyId);

}
